Ext.define("app.customer.agent.rate.form", {
	extend : 'Ext.window.Window',
	title : '编辑信息',
	height : 600,
	width : 800,
	closable : true,
	resizable : false,
	modal : true,
	constrain : true,
	plain : true,
	layout : {
		type : 'border'
	},
	requires : [ 'app.customer.archive.field' ],
	initComponent : function() {
		var me = this;
		me.form = me.createForm();
		Ext.apply(me, {
			items : [ me.form ],
			buttons : [ {
				text : '确认',
				bodyStyle : 'padding:0 0 0 5px',
				handler : function() {
					me.submitForm();
				}
			}, {
				text : '关闭',
				bodyStyle : 'padding:0 0 0 5px',
				handler : function() {
					me.close();
				}
			} ]
		});
		me.callParent(arguments);
	},
	submitForm : function() {
		var me = this;
		var params = {};
		evt.submit(me.form, systemUrl + '/boyon/agent/report/rate/editor', params, function() {
			Ext.Msg.alert('提示', '操作成功');
			me.parentTarget.reloadStore();
			me.close();
		});
	},
	loadData : function(form) {},
	createForm : function() {
		var me = this;
		var fields = me.createField();
		me.form = Ext.create('Ext.form.Panel', {
			layout : 'column',
			region : 'center',
			bodyStyle:'overflow-x:hidden;overflow-y:auto;',
			items : fields,
			listeners : {
				afterrender : function() {
					me.loadData(me.form);
				}
			}
		});
		return me.form;
	},
	createField : function() {
		var me = this;
		var array = new Array();
		utils.pushfieldarray(array, '4', {
			name : 'customerId'
		});
		utils.pushfieldarray(array, 'app.customer.archive.field', {
			name : 'customerName',
			fieldLabel : '代理商',
			parentTarget : me,
			pannelParam : {
				urlType : 3
			},
			columnWidth : .5
		});
		utils.pushfieldarray(array, 'app.widget.value', {
			name : 'reportType',
			beforeLabelTextTpl : required,
			fieldLabel : '报告类型',
			valueField : 'value',
			displayField : 'displayName',
			valueType : 17,
			columnWidth : .5,
			parentTarget : me,
			editable : false,
			allowBlank : false,
			listeners : {
				change : function(o, newValue) {
					var f = me.form.getForm();
					if (newValue == 0) {
						f.findField('rateType').setReadOnly(false);
						f.findField('freeNum').setReadOnly(true);
						f.findField('num').setReadOnly(true);
						f.findField('price').setReadOnly(false);
						f.findField('rate').setReadOnly(false);
					} else {
						f.findField('rateType').setReadOnly(true);
						f.findField('freeNum').setReadOnly(false);
						f.findField('num').setReadOnly(false);
						f.findField('price').setReadOnly(false);
						f.findField('rate').setReadOnly(true);
					}
					f.findField('reportType').setReadOnly(true);
				}
			}
		});
		utils.pushfieldarray(array, 'app.widget.value', {
			name : 'rateType',
			beforeLabelTextTpl : required,
			fieldLabel : '结算类型',
			valueField : 'value',
			displayField : 'displayName',
			valueType : 16,
			columnWidth : .5,
			parentTarget : me,
			editable : false,
			readOnly : true,
			listeners : {
				change : function(o, newValue) {
					var f = me.form.getForm();
					if (newValue == 0) {
						f.findField('rate').setReadOnly(false);
						f.findField('price').setReadOnly(true);
					} else {
						f.findField('price').setReadOnly(false);
						f.findField('rate').setReadOnly(true);
					}
				}
			}
		});
		utils.pushfieldarray(array, '3', {
			name : 'freeNum',
			beforeLabelTextTpl : required,
			fieldLabel : '免费数量',
			readOnly : true,
			columnWidth : .5
		});
		utils.pushfieldarray(array, '3', {
			name : 'num',
			beforeLabelTextTpl : required,
			fieldLabel : '报告数量',
			readOnly : true,
			columnWidth : .5
		});
		utils.pushfieldarray(array, '3', {
			name : 'price',
			beforeLabelTextTpl : required,
			fieldLabel : '金额',
			readOnly : true,
			columnWidth : .5
		});
		utils.pushfieldarray(array, '3', {
			name : 'rate',
			fieldLabel : '比例',
			columnWidth : .5,
			readOnly : true,
			maxLength : 16
		});
		return array;
	},
	callBackCustomer : function(rec) {
		var me = this;
		me.form.getForm().findField('customerId').setValue(rec.get('customerId'));
		me.form.getForm().findField('customerName').setValue(rec.get('customerName'));
	}
});